package core.framework.web.rest.client;

import java.util.List;

/**
 * @author neo
 */
class PathVariableProcessor {
    private final PathVariablePosition[] positions;

    PathVariableProcessor(List<PathVariablePosition> positions) {
        this.positions = positions.toArray(new PathVariablePosition[positions.size()]);
    }

    String url(String pattern, Object[] arguments) {
        String url = pattern;
        for (PathVariablePosition position : positions) {
            url = url.replace("{" + position.name + "}", String.valueOf(arguments[position.index]));
        }
        return url;
    }

    static class PathVariablePosition {
        final int index;
        final String name;

        PathVariablePosition(int index, String name) {
            this.index = index;
            this.name = name;
        }
    }
}
